package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.Produce_ProductBean;
import com.cloudsigns.factorymanager2.produce.iview.IGetProductOrderAssignListView;
import com.cloudsigns.factorymanager2.produce.model.GetProductOrderAssignListModel;
import com.cloudsigns.factorymanager2.produce.model.IGetProductOrderAssignListModel;

import java.util.List;

public class GetProductOrderAssignListPresenter {
    private IGetProductOrderAssignListView view;
    private IGetProductOrderAssignListModel model;
    private Handler handler = new Handler();

    public GetProductOrderAssignListPresenter(IGetProductOrderAssignListView view) {
        this.view = view;
        this.model = new GetProductOrderAssignListModel();
    }

    public void getProductOrderAssignList() {
        view.showLoading();

        model.getProductOrderAssignList(new GetProductOrderAssignListModel.OnProductOrderAssignListListener() {
            @Override
            public void getProductOrderAssignListSuccessed(final List<Produce_ProductBean> productList) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductOrderAssignListSuccessed(productList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getProductOrderAssignListFailed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductOrderAssignListFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
